from GPIB_upperclass import GPIB_wrapper

class E8257D:
	def __init__(self, add="GPIB0::14::INSTR",mod="AM",test=False):
		"""docstring for __init__"""
		self.isTest=test
		self.address=add
		self.modulation=mod
		self.gpib=GPIB_wrapper(add,test)
	
	#Modulation	
	def Set_Modulation(self, freq, amp):#Hz,dB/kHz
		"""
		Parameters:
			- freq: modulation frequency in Hz
			- amp: modulation amplitude (dB -> AM, kHz -> FM)
		"""
		command1=":"+self.modulation+"1:SOURce INT1"
		command2=":"+self.modulation+"1:INTernal1:FREQuency %dKHZ" %freq
		command3=":"+self.modulation+"1:INTernal1:FUNCtion:SHAPe SINE"
		self.gpib.write(command1)
		self.gpib.write(command2)
		self.gpib.write(command3)
		
		if self.modulation=="AM":
			command4=":AM1:TYPE EXP"
			command5=":AM1:EXP %d"%amp
			self.gpib.write(command4)
			self.gpib.write(command5)
		elif self.modulation=="FM":
			command4=":FM1 %dKHZ" %amp
			self.gpib.write(command4)
	
	def Set_Modulation_Output(self,onoff=True,lfout=True):#onoff=true->on
		"""docstring for Set_Intern_Mod_Freq"""
		if onoff==True:
			command1=":"+self.modulation+"1:STATe ON"
		else:
			command1=":"+self.modulation+"1:STATe OFF"
		command2=":LFOutput:SOURce INT1"
		if lfout==True:
			command3=":LFOutput:STATe ON"
		else:
			command3=":LFOutput:STATe OFF"
		command4=":LFOutput:AMPLitude 3.0Vp"
		self.gpib.write(command1)
		self.gpib.write(command2)
		self.gpib.write(command3)
		self.gpib.write(command4)
	
	#RF generator
	def Set_Output_ONOFF(self, onoff=True):#onoff=true->on
		"""docstring for Set_Intern_Mod_Freq"""
		if onoff==True:
			command=":OUTPut ON"
		else:
			command=":OUTPut OFF"
		self.gpib.write(command)
	
	def Set_Frequency(self, freq):#MHz
		"""docstring for Set_Frequency"""
		command=":FREQuency %fMHz" %freq
		self.gpib.write(command)
	
	def Set_Power(self, power):#dBm
		"""docstring for Set_Power"""
		command=":POWer %dDBM" %power
		self.gpib.write(command)
		
class N5181A:
	
	def __init__(self, add="GPIB0::14::INSTR",mod="AM",test=False):
		"""docstring for __init__"""
		self.isTest=test
		self.address=add
		self.modulation=mod
		self.gpib=GPIB_wrapper(add,test)
	
	#Modulation	
	def Set_Modulation(self, freq, amp):#Hz,dB/kHz
		"""
		Parameters:
			- freq: modulation frequency in Hz
			- amp: modulation amplitude (dB -> AM, kHz -> FM)
		"""
		command1=":"+self.modulation+"1:SOURce INT"
		command2=":"+self.modulation+"1:INTernal:FREQuency %dKHZ" %freq
		command3=":"+self.modulation+"1:INTernal:FUNCtion:SHAPe SINE"
		self.gpib.write(command1)
		self.gpib.write(command2)
		self.gpib.write(command3)
		
		if self.modulation=="AM":
			command4=":AM:TYPE EXP"
			command5=":AM:EXP %d"%amp
			self.gpib.write(command4)
			self.gpib.write(command5)
		elif self.modulation=="FM":
			command4=":FM %dKHZ" %amp
			self.gpib.write(command4)
	
	def Set_Modulation_Output(self,onoff=True,lfout=True):#onoff=true->on
		"""docstring for Set_Intern_Mod_Freq"""
		if onoff==True:
			command1=":"+self.modulation+"1:STATe ON"
		else:
			command1=":"+self.modulation+"1:STATe OFF"
		command2=":LFOutput:SOURce INT"
		if lfout==True:
			command3=":LFOutput:STATe ON"
		else:
			command3=":LFOutput:STATe OFF"
		command4=":LFOutput:AMPLitude 3.0Vp"
		self.gpib.write(command1)
		self.gpib.write(command2)
		self.gpib.write(command3)
		self.gpib.write(command4)
	
	#RF generator
	def Set_Output_ONOFF(self, onoff=True):#onoff=true->on
		"""docstring for Set_Intern_Mod_Freq"""
		if onoff==True:
			command=":OUTPut ON"
		else:
			command=":OUTPut OFF"
		self.gpib.write(command)
	
	def Set_Frequency(self, freq):#MHz
		"""docstring for Set_Frequency"""
		command=":FREQuency %fMHz" %freq
		self.gpib.write(command)
	
	def Set_Power(self, power):#dBm
		"""docstring for Set_Power"""
		command=":POWer %dDBM" %power
		self.gpib.write(command)
	
	
	
